<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>订单列表</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="{{URL::asset('layui/css/layui.css')}}"  media="all">
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
</head>
<body>
<fieldset class="layui-elem-field" style="margin-top: 20px;">
    <legend>搜索查询</legend>
    <form class="layui-form" action="">

        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">订单号</label>
                <div class="layui-input-inline">
                    <input type="text" name="order_sn" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">收件人</label>
                <div class="layui-input-inline">
                    <input type="text" name="username"  autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">联系电话</label>
                <div class="layui-input-inline">
                    <input type="text" name="phone"  autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">收货地址</label>
                <div class="layui-input-inline">
                    <input type="tel" name="address"  autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">订单状态</label>
                <div class="layui-input-inline">
                    <select name="order_status" lay-filter="aihao">
                        <option value="all">全部</option>
                        <option value="0">待支付</option>
                        <option value="1">待发货</option>
                        <option value="2">待收货</option>
                        <option value="3">已签收</option>
                        <option value="4">已评价</option>
                        <option value="7">已退款</option>
                        <option value="-1">已取消</option>
                    </select>
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">支付方式</label>
                <div class="layui-input-inline">
                    <select name="payment" lay-filter="aihao">
                        <option value="all">全部</option>
                        <option value="integral">积分支付</option>
                        <option value="wechat">微信支付</option>
                    </select>
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">开始时间</label>
                <div class="layui-input-inline">
                    <input type="text" name="start_date" id="date1" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">结束日期</label>
                <div class="layui-input-inline">
                    <input type="text" name="end_date" id="date2" autocomplete="off" class="layui-input">
                </div>
                <div class="layui-input-inline">
                    <button class="layui-btn" lay-submit="" lay-filter="demo1">搜索</button>
                    <button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="demo2">导出</button>
                </div>
            </div>
        </div>
    </form>
</fieldset>




<table class="layui-hide" id="test" lay-filter="test"></table>


<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>


<script src="{{URL::asset('layui/layui.js')}}" charset="utf-8"></script>
<script src="{{URL::asset('js/jquery-3.1.1.min.js')}}"></script>
<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->

<script>
    layui.use(['table','form','laydate'], function(){
        var table = layui.table,
            laydate = layui.laydate,
            form = layui.form;

        //日期
        laydate.render({
            elem: '#date1'
        });
        laydate.render({
            elem: '#date2'
        });

        table.render({
            elem: '#test'
            ,url:'/admin/order/api/list'
            ,title: '订单数据表'
            ,cols: [[
                {type: 'checkbox', fixed: 'left'}
                ,{field:'id', title:'ID', width:80, fixed: 'left', unresize: true, sort: true}
                ,{field:'order_sn', title:'订单号', width:200}
                ,{field:'order_amount', title:'订单金额', width:100}
                ,{field:'pay_amount', title:'实付金额', width:100}
                ,{field:'payment', title:'支付方式', width:120,templet:function (d) {
                        if (d.payment=='wechat'){
                            return '微信支付';
                        } else {
                            return '积分支付';
                        }
                    }}
                ,{field:'goods_num', title:'购买数量', width:100}
                ,{field:'username', title:'收件人', width:100}
                ,{field:'phone', title:'联系电话', width:150}
                ,{field:'address', title:'收货地址', width:250}
                ,{field:'order_status', title:'订单状态', width:120,templet:function (d) {
                        if (d.order_status==0){
                            return '待支付';
                        } else if(d.order_status==1) {
                            return '待发货';
                        } else if (d.order_status==2){
                            return '待收货';
                        } else if (d.order_status==3){
                            return '已签收';
                        } else if (d.order_status==4){
                            return '已评价';
                        } else if (d.order_status==7){
                            return '已退款';
                        } else if(d.order_status==-1){
                            return '已取消';
                        } else {
                            return '状态异常';
                        }
                    }}
                ,{field:'order_time', title:'下单时间', width:200}
                ,{fixed: 'right', title:'操作', width:120, templet:function (d) {
                    var jd = '<a class="layui-btn layui-btn-xs layui-btn-normal" lay-event="detail">查看</a>';
                        if (d.order_status==0){
                            jd+='<a class="layui-btn layui-btn-xs layui-btn-primary" lay-event="close">取消</a>';
                        } else if (d.order_status==1) {
                            jd+='<a class="layui-btn layui-btn-xs" lay-event="send">发货</a>';
                        }
                        return jd;
                    }}
            ]]
            ,page: true
        });

        //监听行工具事件
        table.on('tool(test)', function(obj){
            var data = obj.data;
            //console.log(obj)
            if(obj.event === 'close'){
                layer.confirm('确认取消该订单?', function(index){
                    $.post('/admin/order/api/close',{"id":data.id},function (d) {
                        if (d.code==200){
                            layer.msg("订单取消成功");
                            setTimeout(function () {
                                window.location.reload();
                            },500)
                        } else{
                            layer.msg("订单取消失败");
                        }
                    });
                    obj.del();
                    layer.close(index);
                });
            } else if(obj.event === 'send'){
                layer.open({
                    type:2,
                    title:"订单发货",
                    area:["90%","40%"],
                    content:'/admin/order/send/html?id='+data.id
                });
            } else if (obj.event === 'detail'){
                layer.open({
                    type:2,
                    area:["90%","80%"],
                    title:"订单详情",
                    content:'/admin/order/detail/html?id='+data.id
                });
            }
        });

        //监听提交
        form.on('submit(demo1)', function(data){
            var param = data.field;
            //执行重载
            table.reload('test', {
                page: {
                    curr: 1 //重新从第 1 页开始
                }
                ,where: {
                    order_sn: param.order_sn,
                    phone:param.phone,
                    username:param.username,
                    address:param.address,
                    order_status:param.order_status,
                    payment:param.payment,
                    start_date:param.start_date,
                    end_date:param.end_date
                }
            });
            return false;
        });

        //监听提交
        form.on('submit(demo2)', function(data){
            var param = data.field;
            window.location.href = '/admin/order/api/export?order_sn='+param.order_sn+'&phone='+param.phone+'&username='+param.username+'&address='+param.address+'&order_status='+param.order_status+'&payment='+param.payment+'&start_date='+param.start_date+'&end_date='+param.end_date;
            return false;
        });
    });
</script>

</body>
</html>